package cn.example.zjgsu.controller;

import cn.example.zjgsu.exception.MyException;
import cn.example.zjgsu.pojo.Plan;
import cn.example.zjgsu.pojo.result.JsonData;
import cn.example.zjgsu.service.OneDayFoodPageServer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author xuejiahui
 * @date 2020/3/26 -19:50
 */
@RestController
@RequestMapping({"/v1/api/onedayyfoodpage"})
@Api(description = "一日美食接口")
public class OneDayFoodPageController {
    @Autowired
    OneDayFoodPageServer oneDayFoodPageServer;

    @ApiOperation("新增一个一日美食计划")
    @PostMapping(value = "/insertplan")
    public JsonData insertPlan(@RequestBody  Plan plan){
        try {
            return JsonData.success(oneDayFoodPageServer.insertPlan(plan));
        }catch (MyException e){
            return JsonData.fail(e.getMessage());
        }
    }

    @ApiOperation("根据计划ID查看具体一日美食计划")
    @GetMapping(value = "/getplanbyid")
    public JsonData getPlanById(int planid){
        try {
            return JsonData.success(oneDayFoodPageServer.getPlanByPlanId(planid));
        }catch (NullPointerException e){
            return JsonData.fail("请传入正确的id");
        }
    }

    @ApiOperation("根据用户账号搜索一日美食计划")
    @GetMapping(value = "/getbriefplanbyuserid")
    public JsonData getPlansByUserId(String userid){
        try {
            return JsonData.success(oneDayFoodPageServer.getPlanByUserId(userid));
        }catch (MyException e){
            return JsonData.fail(e.getMessage());
        }
    }

    @ApiOperation("根据城市id获取推荐食记来生成一日计划")
    @GetMapping(value = "/getrecommendfoodrecord")
    public JsonData getRecommendFoodRecord(int cityid){
        try {
            return JsonData.success(oneDayFoodPageServer.getRecommendFoodRecord(cityid));
        }catch (MyException e){
            return JsonData.fail(e.getMessage());
        }
    }

    @ApiOperation("根据一日计划id删除一日计划")
    @GetMapping(value = "/deleteplan")
    public JsonData deletePlanById(int planid){
        return JsonData.success(oneDayFoodPageServer.deletePlanById(planid));
    }

    @ApiOperation("根据店铺id获取店铺周围的风景")
    @GetMapping(value = "/getscenery")
    public JsonData getSceneryByShopId(int shopid){
        return JsonData.success(oneDayFoodPageServer.getSceneryByShopId(shopid));
    }

    @ApiOperation("更新一日计划")
    @PostMapping(value = "/updateplan")
    public JsonData updatePlan(@RequestBody  Plan plan){
        return JsonData.success(oneDayFoodPageServer.updatePlan(plan));
    }

    @ApiOperation("根据食记标题模糊查询食记")
    @GetMapping(value = "/queryfoodrecord")
    public JsonData fuzzyQueryFoodRecord(String foodrecordtitle){
        try {
            return JsonData.success(oneDayFoodPageServer.fuzzyQueryFoodRecord(foodrecordtitle));
        } catch (MyException e) {
            return JsonData.fail(e.getMessage());
        }
    }

}
